package com.keguoyu.easymvp.commons.receiver;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class MultiReceiverImpl<T> implements ReceiverInterface<T> {

  private final List<ReceiverInterface<T>> mReceiverInterfaces = new ArrayList<>();

  public MultiReceiverImpl(List<ReceiverInterface<T>> receiverInterfaces) {
    mReceiverInterfaces.addAll(receiverInterfaces);
  }

  @Override
  public void receive(T target, Object wrapper) {
    for (ReceiverInterface<T> receiverInterface : mReceiverInterfaces) {
      receiverInterface.receive(target, wrapper);
    }
  }

  @Override
  public Set<String> getAllNames() {
    Set<String> allNames = new HashSet<>();
    for (ReceiverInterface<T> receiverInterface : mReceiverInterfaces) {
      allNames.addAll(receiverInterface.getAllNames());
    }
    return allNames;
  }

  @Override
  public Set<Class> getAllTypes() {
    Set<Class> allTypes = new HashSet<>();
    for (ReceiverInterface<T> receiverInterface : mReceiverInterfaces) {
      allTypes.addAll(receiverInterface.getAllTypes());
    }
    return allTypes;
  }

  @Override
  public void reset(T target) {
    for (ReceiverInterface<T> receiverInterface : mReceiverInterfaces) {
      receiverInterface.reset(target);
    }
  }
}
